package com.jingming.consult.fragment

import android.os.Bundle
import android.view.View
import com.jingming.consult.R
import com.jingming.consult.activity.LoginActivity
import com.jingming.consult.base.BaseFragment
import com.jingming.consult.eventbus.EventBusKeys
import com.jingming.consult.eventbus.EventBusMessage
import com.jingming.consult.eventbus.EventBusUtils
import kotlinx.android.synthetic.main.fragmenttmy.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 * 我的页面
 */
class MyFragment : BaseFragment() {
    override fun getLayoutid(): Int {
        return R.layout.fragmenttmy
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        EventBusUtils.register(this)
    }
    override fun onCreateView(savedInstanceState: Bundle?) {
        super.onCreateView(savedInstanceState)

        tvLogin.setOnClickListener {
            LoginActivity.startLoginActivity(activity!!)
        }
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onEvent(message: EventBusMessage) {
        when (message.key) {
            EventBusKeys.LOGINSUCCESS -> {
                tvLogin.visibility = View.GONE
                tvUserName.visibility = View.VISIBLE
                tvUserName.text = message.get("username")
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBusUtils.unRegister(this)
    }
}